﻿using UnityEngine;
using System.Collections;

public class TrackPieceController : MonoBehaviour {

	private bool m_inAction = false;

	void Start ()
	{
	
	}
	
	void Update ()
	{
		bool allHidden = true;
		Component[] components = gameObject.GetComponentsInChildren(typeof(Renderer));
		foreach (Component component in components)
		{
			Renderer componentRenderer = (Renderer)component;
			if (componentRenderer.isVisible)
			{
				allHidden = false;
				break;
			}
		}

		if (allHidden && m_inAction)
		{
			Destroy(gameObject);
		}

		if (!allHidden && !m_inAction)
		{
			m_inAction = true;
		}
	}
}
